#!/usr/bin/perl

#-------------------------------------------------------------------------------
#--
#-- Module      :  BRFinder
#-- Copyright   :  (c) Lakshmi Narasimhan T V
#-- License     :  GNU GPLv3
#--
#-- Maintainer  :  <lakshminaras2002 at gmail dot com>
#-- Stability   :  provisional
#-- Portability :  portable
#--
#--
#--
#---------------------------------------------------------------------------------

use strict;
use warnings;
use File::Basename;

my $PROG_DIR;

BEGIN
{
my $TEMP_DIR = File::Basename::dirname($0);
$PROG_DIR = abs_path($TEMP_DIR);
push @INC,$PROG_DIR;
}

sub stripws($);
sub getbuildrequires($);

sub getbuildrequires($)
{
  my $specfile = shift;
  my @allstrings = `grep BuildRequires $specfile`;
  my @buildrequires = ();
  foreach my $string (@allstrings)
  {
    $string = stripws($string);
    my @splitstrings = split /(:|,)/,$string;
    foreach my $splitstr (@splitstrings)
    {
      $splitstr = stripws($splitstr);
      if($splitstr =~ m/(^ghc)(.*)-(devel$)/
           || $splitstr =~ m/(^ghc)(.*)-(prof$)/) # Is it really what we want, then it should start with ghc and end with devel
      {
         # drop devel or prof from the end of the string
         my $dep = $1.$2;
         push @buildrequires,$dep;
      }
    }
  }
  return @buildrequires;
}

1;
